package com.example.asus.homework11.model;

import com.example.asus.homework11.bean.LoginBean;
import com.example.asus.homework11.bean.RegisterBean;
import com.example.asus.homework11.listener.RetrofitListener;
import com.example.asus.homework11.retrofitservice.LoginService;
import com.example.asus.homework11.retrofitservice.RegisterService;


import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 彭立翔 on 2018/10/11.
 * Coder Level:MAX.
 */

public class RegisterModel {
    private RegisterService service;
    private Retrofit retrofit;
    private static final String BASE_URL = "http:/172.24.10.175:8080/foodService/";
    public RegisterModel(){
        retrofit = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
        service = retrofit.create(RegisterService.class);

    }
    public void userRegister(String username, String password,String mobilenum,String comment ,String address ,final RetrofitListener listener){
        Call call = service.userRegister(username,password,mobilenum,comment,address);
        Callback<RegisterBean> callback = new Callback<RegisterBean>() {
            @Override
            public void onResponse(Call<RegisterBean> call, Response<RegisterBean> response) {
                listener.onSuccess(response.body(),1);
                System.out.print(response.body().toString());
            }

            @Override
            public void onFailure(Call<RegisterBean> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
}
